#include "RsGisLibClbCalIrradianceImgElevLut.h"
#include "ExtensionManager.h"
#include "ExtensionSession.h"
#include <QVariant>

RsGisLibClbCalIrradianceImgElevLut::RsGisLibClbCalIrradianceImgElevLut(RsgisPortal* ClientPortal, QWidget *parent)
{
	ui = new Ui::RsGisLibClbCalIrradianceImgElevLut();
	ui->setupUi(this);

	Portal = ClientPortal;

	connect(ui->pushButton_DataMaskFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_DataMaskFilePath_clicked()));
	connect(ui->pushButton_DEMFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_DEMFilePath_clicked()));
	connect(ui->pushButton_InciAngleFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_IncAngleFilePath_clicked()));
	connect(ui->pushButton_SlopeFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_SlopeFilePath_clicked()));
	connect(ui->pushButton_SurfReflFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_SrefFilePath_clicked()));
	connect(ui->pushButton_ShadowFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_ShadowFilePath_clicked()));
	connect(ui->pushButton_CoeffLutFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_CoeffLutFilePath_clicked()));
	connect(ui->pushButton_OutputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_OutputFilePath_clicked()));
	connect(ui->pushButton_CalIrradianceImgElevLut, SIGNAL(clicked()), this, SLOT(on_action_Button_CalIrradianceImgElevLut_clicked()));

	ui->textBrowser_ParameterDescription->setText(
		"Solar Zenith - is a float with the solar zenith for the whole scene\nScale Factor - is a float which can be used to scale the output pixel values(e.g., multiple by 1000), set as 1 for no scaling\nGdal Format - string specifying the output image format"
	);

	ui->textBrowser_ParameterDescription->setEnabled(false);

	ui->lineEdit_DataMaskFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\DataMask.tif");
	ui->lineEdit_DEMFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\DEM.tif");
	ui->lineEdit_InciAngleFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\InciAngle.tif");
	ui->lineEdit_SlopeFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\Slope.tif");
	ui->lineEdit_SurfReflFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\SurfRefl.tif");
	ui->lineEdit_ShadowFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\Shadow.tif");
	ui->lineEdit_CoeffLutFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\CoeffLut.tif");
	ui->lineEdit_OutputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\TestCalIrradianceImgElevLut.tif");
	ui->lineEdit_ScaleFactor->setText("0.0");
	ui->lineEdit_SolarZenith->setText("0.0");
	ui->lineEdit_GdalFormat->setText("GTIFF");

	ui->lineEdit_Priority->setText("16");
}

void RsGisLibClbCalIrradianceImgElevLut::on_action_Button_DataMaskFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_DataMaskFilePath->setText(str.toUtf8());
}

void RsGisLibClbCalIrradianceImgElevLut::on_action_Button_DEMFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_DEMFilePath ->setText(str.toUtf8());
}

void RsGisLibClbCalIrradianceImgElevLut::on_action_Button_IncAngleFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_InciAngleFilePath->setText(str.toUtf8());
}

void RsGisLibClbCalIrradianceImgElevLut::on_action_Button_SlopeFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_SlopeFilePath->setText(str.toUtf8());
}

void RsGisLibClbCalIrradianceImgElevLut::on_action_Button_SrefFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_SurfReflFilePath->setText(str.toUtf8());
}

void RsGisLibClbCalIrradianceImgElevLut::on_action_Button_ShadowFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_ShadowFilePath->setText(str.toUtf8());
}

void RsGisLibClbCalIrradianceImgElevLut::on_action_Button_CoeffLutFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_CoeffLutFilePath->setText(str.toUtf8());
}

void RsGisLibClbCalIrradianceImgElevLut::on_action_Button_OutputFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_OutputFilePath->setText(str.toUtf8());
}

void RsGisLibClbCalIrradianceImgElevLut::on_action_Button_CalIrradianceImgElevLut_clicked()
{
	{
		if (ui->lineEdit_DataMaskFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Data Mask File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_DEMFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "DEM File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_SlopeFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Slope File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_InciAngleFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Inci Angle File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_SurfReflFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Surf Refl File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_ShadowFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Shadow File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_CoeffLutFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Coeff Lut File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_OutputFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Output File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_ScaleFactor->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Scale Factor is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_SolarZenith->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Solar Zenith is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_Priority->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Priority is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}
	}

	QList<QVariant> SysParaList;
	SysParaList << QVariant(QString("RsGisLib"));
	SysParaList << QVariant(QString("imageCalibration"));
	SysParaList << QVariant(int(ui->lineEdit_Priority->text().toInt()));

	QList<QVariant> AlgParaList;
	AlgParaList << QVariant(QString("executeCalcIrradianceElevLUT"));
	AlgParaList << QVariant(QString(ui->lineEdit_DataMaskFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_DEMFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_InciAngleFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_SlopeFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_SurfReflFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_ShadowFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_CoeffLutFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_OutputFilePath->text()));
	AlgParaList << QVariant(double(ui->lineEdit_ScaleFactor->text().toDouble()));
	AlgParaList << QVariant(double(ui->lineEdit_SolarZenith->text().toDouble()));
	AlgParaList << QVariant(QString(ui->lineEdit_GdalFormat->text()));

	QVariantList ArgList;
	ArgList << (QVariant)SysParaList;
	ArgList << (QVariant)AlgParaList;

	Portal->goAhead(ArgList);
}
